package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import Member1.Data6;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class StringTest3 extends JFrame {

	private JPanel contentPane;
	private JLabel lblNewLabel;
	private JTextField str;
	private JButton btnNewButton;
	private JLabel lblNewLabel_1;
	private JScrollPane scrollPane;
	private JTextArea result;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StringTest3 frame = new StringTest3();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public StringTest3() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getLblNewLabel());
		contentPane.add(getStr());
		contentPane.add(getBtnNewButton());
		contentPane.add(getLblNewLabel_1());
		contentPane.add(getScrollPane());
	}

	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("검색어");
			lblNewLabel.setBounds(31, 27, 57, 15);
		}
		return lblNewLabel;
	}
	private JTextField getStr() {
		if (str == null) {
			str = new JTextField();
			str.setBounds(100, 24, 179, 21);
			str.setColumns(10);
		}
		return str;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("검색");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					String[] word = {"love","sex","사랑","야동"};
					try{
						String temp = "";
						boolean flag=false;
						int pos = -1;
						for(int i=0; i<word.length; i++){
							if(str.getText().contains(word[i])){
								flag = true;
								pos = 1;
								break;
							}	
						}
						if(flag){
							temp = "\""+str.getText()+"\"\n에는 금지어"+word[pos]+"이(가) 포함되어 있습니다";
						}else{
							temp = "검색이 완료되었습니다.\n\n";
						}
						result.append(temp+"\n");
//						for(int i=0; i<word.length; i++){
//							boolean flag = true; 
//							if(str.getText().equals("")) flag=false;    
//							else if(str.getText().contains("love")) flag=false;
//					        else if(str.getText().contains("sex")) flag=false;
//					        else if(str.getText().contains("사랑")) flag=false;
//					        else if(str.getText().contains("야동")) flag=false;
//					       
//					        
//							if(flag){						
//							    str.getText().contains(word[i]);
//								result.append("\n검색되었습니다");
//							} else {result.append("\n 금지어가 포함되어있습니다.");
//						   }break;
//				     }
						}catch(Exception ex){
						result.append("\n내용을 입력해주세요");
					}
				}
			});
			btnNewButton.setBounds(309, 23, 97, 23);
		}
		return btnNewButton;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("검색결과");
			lblNewLabel_1.setBounds(31, 91, 57, 30);
		}
		return lblNewLabel_1;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(41, 131, 365, 121);
			scrollPane.setViewportView(getResult());
		}
		return scrollPane;
	}
	private JTextArea getResult() {
		if (result == null) {
			result = new JTextArea();
		}
		return result;
	}
}
